<?php

/**
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 * http://www.gnu.org/copyleft/gpl.html
 */
 


/**
 *  @file
 *  @Author Samuel Maura
 *  Another part of the database abstraction layer
 *  to run queries and provide some basic utility functions 
 *  specific to MySql
 *
 */
 
require_once("".$_SERVER['DOCUMENT_ROOT']."/xenix/models/dbManager.inc");

class DBQuery extends DBManager{
  
  private $connection;
  private $query_string;
  private $result;
  
 protected function queryString($query_string){
    $this->query_string = $query_string;
    $this->connection = DBManager::connect();
    $this->runQuery();  
    $this->errorCheck();
    //echo "<br/>".$query_string."<br/>";
  }
  
 protected function runQuery(){
    $this->result = @mysqli_query( $this->connection,$this->query_string);
  }
  
  
  protected function rowCount(){
    return mysqli_num_rows($this->result);
  }
  
  protected function getRowSet(){
   $dataSet = array();
   
    if ($this->rowCount() > 0){
      while($row = @mysqli_fetch_assoc($this->result) ){
        $dataSet[] = $row;
      }
      return $dataSet;
    }
    else{
      return NULL;
    }
  }
  
  private function errorCheck(){
    if (!$this->result){
      trigger_error("Query failed: ".mysqli_errno($this->connection)." \n
      ".mysqli_error($this->connection)." \n Query: ".$this->query_string."",E_USER_ERROR);
    }
    
  }
  
}

?>